const baseMixin = {
  data() {
    return {
      title: "这个是公用标题",
    };
  },
  methods: {
    onClick() {
      console.log("我被点击了");
    },
    randomHexColor() {
      //随机生成十六进制颜色
      var hex = Math.floor(Math.random() * 16777216).toString(16); //生成ffffff以内16进制数
      while (hex.length < 6) {
        //while循环判断hex位数，少于6位前面加0凑够6位
        hex = "0" + hex;
      }
      return "#" + hex; //返回‘#'开头16进制颜色
    },
    dateFormat(date) {
      let format = "yyyy-MM-dd hh:mm:ss";
      if (date !== "Invalid Date") {
        var o = {
          "M+": date.getMonth() + 1, // month
          "d+": date.getDate(), // day
          "h+": date.getHours(), // hour
          "m+": date.getMinutes(), // minute
          "s+": date.getSeconds(), // second
          "q+": Math.floor((date.getMonth() + 3) / 3), // quarter
          S: date.getMilliseconds(), // millisecond
        };
        if (/(y+)/.test(format)) {
          format = format.replace(
            RegExp.$1,
            (date.getFullYear() + "").substr(4 - RegExp.$1.length)
          );
        }
        for (var k in o) {
          if (new RegExp("(" + k + ")").test(format)) {
            format = format.replace(
              RegExp.$1,
              RegExp.$1.length === 1
                ? o[k]
                : ("00" + o[k]).substr(("" + o[k]).length)
            );
          }
        }
        return format;
      }
      return "";
    },
    getNowTime() {
      let dateTime;
      let yy = new Date().getFullYear();
      let mm = new Date().getMonth() + 1;
      let dd = new Date().getDate();
      dateTime = yy + "-" + mm + "-" + dd;
      console.log(dateTime);
      return dateTime;
    },
    initEcharts(legend,week,data) {

      const option = {
        title: {
          text: "",
        },
        tooltip: {
          trigger: "axis",
        },
        legend: {
          data: legend,
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        toolbox: {
			show: false,
          feature: {
            saveAsImage: {},
          },
        },
        xAxis: {
          type: "category",
          boundaryGap: false,
          data: week,
        },
        yAxis: {
          type: "value",
        },
        series: data,
      };
      const chartDom = document.getElementById("initechart");
      const myChart = this.$echarts.init(chartDom);
      myChart.setOption(option);
      window.onresize = function () {
        myChart.resize();
      };
    },
	initpPie(data){
		const	option = {
			// legend: {
			//       orient: 'vertical',
			//       left: 'left',
			//       formatter: function (name) {
				  // 		return name; 
				  // 	},
			//   },
			tooltip : {
					  trigger: 'item',
					  formatter: "{a} <br/>{b} : {d}%"
				  },
			toolbox: { // 下载按钮
			  show: false,
			  feature: {
				mark: { show: true },
				dataView: { show: true, readOnly: false },
				restore: { show: true },
				saveAsImage: { show: true }
			  }
			},
			series: [
			  {
				name: 'Nightingale Chart',
				type: 'pie',
				center: ['50%', '50%'],
				itemStyle: {
					borderRadius: 10,
					borderColor: '#fff',
					borderWidth: 2
				  },
				label: {
						normal: {
							show: true,
							position: 'inner',
						   formatter: function (item) {
								return  item.name + item.value +'%'
							  },
							fontSize: 7
						}
					},
				data: data
			  }
			]
		  };
		  const chartDom = document.getElementById("pie");
      const myChart = this.$echarts.init(chartDom);
      myChart.setOption(option);
      window.onresize = function () {
        myChart.resize();
      };
	}
  },
};

export default baseMixin;
